package com.atguigu.jxc.vo;

import com.atguigu.jxc.entity.GoodsType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
public class GoodsTypeVo {
    /**
     * "id": 4,
     * "text": "家电",
     * "state": "closed",
     * "iconCls": "goods-type",
     * "attributes": {
     * "state": 1
     * },
     * "children": [
     */
    private Integer id;
    private Integer  pid;
     private String text;
     private String state;
     private String iconCls="goods-type";
     private Map<String,Integer> attributes;
     private List<GoodsTypeVo> children = new ArrayList<>();

    /**
     * GoodsType 转为 GoodsTypeVo
     * @param goodsType
     * @return
     */
    public static GoodsTypeVo convertSingle(GoodsType goodsType) {


        GoodsTypeVo goodsTypeVo = new GoodsTypeVo();

        goodsTypeVo.setPid(goodsType.getPId());
        goodsTypeVo.setId(goodsType.getGoodsTypeId());
        goodsTypeVo.setText(goodsType.getGoodsTypeName());
        if (Integer.valueOf(1).equals(goodsType.getGoodsTypeState())){
            goodsTypeVo.setState("closed");
        }else  if (Integer.valueOf(0).equals(goodsType.getGoodsTypeState())){
            goodsTypeVo.setState("open");
        }

        HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("state",goodsType.getGoodsTypeState());
        goodsTypeVo.setAttributes(objectObjectHashMap);

        return goodsTypeVo;

    }

}
